//
//  lvfjAnimationRefresh.m
//  lvfj
//
//  Created by 吕飞俊 on 15/10/30.
//  Copyright © 2015年 Goudu KuaiEx Technology(Shenzhen)Co.,ltd. All rights reserved.
//   _          ______   _      _
//  | |        |  ____| (_)    | |
//  | |  __   _| |__ ___ _     | |_   _ _ __
//  | |  \ \ / /  __/ _ \ |_   | | | | | '_ \
//  | |___\ V /| | |  __/ | |__| | |_| | | | |
//  |______\_/ |_|  \___|_|\____/ \__,_|_| |_|
//

#import "lvfjAnimationRefresh.h"

#define IOS7 (floor(NSFoundationVersionNumber) > NSFoundationVersionNumber_iOS_6_1 && floor(NSFoundationVersionNumber) <= NSFoundationVersionNumber_iOS_7_1)
#define IOS8  ([[[UIDevice currentDevice] systemVersion] compare:@"8" options:NSNumericSearch] != NSOrderedAscending)
#define IPHONE6PLUS ((UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) && [[UIScreen mainScreen] nativeScale] == 3.0f)

@implementation lvfjAnimationRefresh

+(void)animationCommonSetViewScrollView:(UIScrollView *)scrollView
                     loadingImgsGifName:(NSString *)loadingImgsGifName
                    progressImgsGifName:(NSString *)progressImgsGifName
                                  block:(void (^)())success{
    [scrollView addPullToRefreshActionHandler:^{
        success();
    } ProgressImagesGifName:progressImgsGifName LoadingImagesGifName:loadingImgsGifName ProgressScrollThreshold:70 LoadingImageFrameRate:30];
    
    if(IOS7)
        [scrollView addTopInsetInPortrait:0 TopInsetInLandscape:52];
    else if(IOS8){
        CGFloat landscapeTopInset = 32.0;
        if(IPHONE6PLUS)
            landscapeTopInset = 44.0;
        [scrollView addTopInsetInPortrait:0 TopInsetInLandscape:landscapeTopInset];
    };
}

+(void)animationStopRefreshScrollView:(UIScrollView *)scrollView{
    [scrollView stopPullToRefreshAnimation];
}

+(void)animationStartRefreshScrollView:(UIScrollView *)scrollView{
    [scrollView triggerPullToRefresh];
}

@end
